import sys
import datetime
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from tools import *
from PyQt5.QtMultimedia import *
from window import *
import json
import time
import shutil
import ctypes

"""
窗口创建流程：
1 在线程初始化中创建窗口对象
2 在线程中创建显示函数
3 在有打开按钮的窗口中创建一个打开信号
4 打开信号连接线程中的显示函数
5 创建发送信号函数并连接按钮
"""


class remind_thread(QThread):
    remind_signal = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.remind_window_list = []

    def open_remind_window(self, id):
        self.remind_window = remind_window(id)
        self.remind_window_list.append(self.remind_window)
        self.remind_window_list[len(self.remind_window_list) - 1].show()
        self.play_sound()

    # 播放提示音
    def play_sound(self):
        url = QUrl.fromLocalFile("../static/提示音.mp3")
        content = QMediaContent(url)
        player = QMediaPlayer()
        player.setMedia(content)
        player.play()
        time.sleep(0.4)

    # 线程保持
    def run(self):
        while 1:
            time.sleep(1)
            self.remind_signal.emit("")


class Thread(QThread):
    # 创建自定义信号
    close_window_signal = pyqtSignal(str)  # 关闭窗口信号
    change_address_signal = pyqtSignal(str)  # 修改地址信号

    change_background_signal = pyqtSignal(str)  # 修改背景信号
    change_teaching_week_address_signal = pyqtSignal(str)  # 修改教学周信号
    update_main_window_signal = pyqtSignal(str)  # 修改日历主界面
    time_update_signal = pyqtSignal(str)  # 定时刷新主界面信号

    def __init__(self):
        super().__init__()

        # 创建窗口
        self.w_setting = Settingwindow()
        self.w_schedule = Schedulewindow()
        self.w_event = Schedule_msg_window()

        # 信号与槽绑定
        self.w_setting.change_backgruond_signal.connect(self.change_background)
        self.w_setting.change_teaching_week_address_signal.connect(self.change_teaching_address_week)
        self.close_window_signal.connect(self.close_window)
        self.w_schedule.open_add_event_window_signal.connect(self.open_event_window)

        # 其他
        self.w_schedule_is_show = 0

    """打开和关闭窗口函数"""

    # 打开日程对话框窗口
    def open_schedule_window(self, position):
        if self.w_schedule_is_show == 0:
            self.w_schedule.close()
            self.w_schedule = Schedulewindow(
                position.split(",")[2] + "," + position.split(",")[3] + "," + position.split(",")[4])
            self.w_schedule.open_add_event_window_signal.connect(self.open_event_window)
            self.w_schedule.show()
            self.w_schedule.move(int(position.split(",")[0]) + 2, int(position.split(",")[1]))
            self.w_schedule_is_show = 1
        else:
            self.w_schedule.close()
            self.w_schedule_is_show = 0

    # 打开时间修改窗口
    def open_time_window(self):
        self.w_time.show()

    # 打开设置界面
    def open_setting_window(self):
        self.w_setting.show()

    # 打开事件界面
    def open_event_window(self, s):
        self.w_event = Schedule_msg_window(s)
        self.w_event.update_signal.connect(self.update_main_window)
        self.w_event.show()

    # 打开搜索界面
    def open_search_window(self, s):
        self.search_window = search_list_frame(s)
        self.search_window.open_event_window_signal.connect(self.open_event_window)
        self.search_window.show()

    # 关闭设置界面
    def close_window(self):
        self.w_setting.close()
        self.w_schedule.close()

    """修改信号发送函数"""

    def update_main_window(self):
        self.update_main_window_signal.emit("")

    # 发送修改天气地址信号
    def change_weather(self, address):
        self.change_address_signal.emit(address)

    # 发送修改时间信号
    def change_time(self, time):
        self.change_time_signal.emit(time)

    # 修改背景
    def change_background(self, background_img):
        self.change_background_signal.emit(background_img)

    # 修改教学周和默认地址信号发送函数
    def change_teaching_address_week(self):
        self.change_teaching_week_address_signal.emit("")

    # 线程保持
    def run(self):
        while 1:
            time.sleep(10)
            self.time_update_signal.emit("")


class MainWindow(QWidget):
    # 自定义信号
    change_address_window_signal = pyqtSignal(str)  # 打开修改地点窗口信号
    change_time_window_signal = pyqtSignal(str)  # 打开修改天气窗口信号
    setting_window_signal = pyqtSignal(str)  # 打开设置窗口信号
    open_schedule_window_signal = pyqtSignal(str)  # 打开日程对话框信号
    open_remind_window_signal = pyqtSignal(str)  # 打开提醒框信号

    def __init__(self):
        super().__init__()

        self.desktop = QApplication.desktop()

        # 获取当天的日期
        self.gregorian_calendar = "%s年%s月%s日" % (datetime.date.today().year, datetime.date.today().month
                                                 , datetime.date.today().day)

        # 获取当天的日期对象
        self.day = get_day(self.gregorian_calendar)

        # 日历显示的月
        self.search_mouth = self.gregorian_calendar.split("月")[0] + "月"

        # 日历列表
        self.calendar_list = []

        # 教学周列表
        self.teaching_week_list = []

        # 今日提醒事件列表
        self.remind_event_list = []

        # 天气地址
        self.address = read_setting("地址")

        # 搜索栏状态
        self.search_bar_type = 0

        self.init_ui()

        self.get_event_list()

    # 初始化ui函数
    def init_ui(self):
        self.resize(800, 600)  # 设置窗口大小
        self.setFixedSize(800, 600)  # 固定大小

        self.setWindowFlags(Qt.FramelessWindowHint)  # 去边框化
        self.setAttribute(Qt.WA_TranslucentBackground)  # 设置主窗口透明
        self.setWindowIcon(QIcon("../static/img/logo1.png"))

        ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("myappid")

        # 设置背景
        self.set_background()

        # 设置logo
        self.set_logo()

        # 设置左上角日期信息
        self.set_date_msg()

        # 设置操作栏
        self.set_action_bar()

        # 设置天气提醒
        self.set_weather(self.address)

        # 设置灰色框以及里面的内容
        self.set_grey_frame()

        # 设置搜索框
        self.set_search_bar()

        # 设置字段
        self.set_field()

        # 设置日历日期
        self.set_calendar()

        self.thread = Thread()
        # 连接线程信号与槽
        self.thread.change_address_signal.connect(self.change_weather)
        self.thread.change_background_signal.connect(self.change_background)
        self.thread.change_teaching_week_address_signal.connect(self.change_teaching_week_address)
        self.thread.update_main_window_signal.connect(self.update_main_window_remind_event)
        self.thread.time_update_signal.connect(self.time_update)
        self.thread.w_setting.btn_reset.clicked.connect(self.reset)
        # 连接本地信号与槽
        self.change_time_window_signal.connect(self.thread.open_time_window)
        self.open_schedule_window_signal.connect(self.thread.open_schedule_window)
        self.setting_window_signal.connect(self.thread.open_setting_window)

        self.thread.start()

        self.remind_thread = remind_thread()

        self.remind_thread.remind_signal.connect(self.remind)

        self.open_remind_window_signal.connect(self.remind_thread.open_remind_window)

        self.remind_thread.start()

    # 设置背景函数
    def set_background(self):
        pix = QPixmap('../static/img/%s' % read_setting("背景"))  # 取图
        self.background = QLabel(self)
        self.background.setGeometry(0, 0, 800, 600)
        self.background.setPixmap(pix)  # 把图片放入label
        self.background.setScaledContents(True)  # 自适应QLabel大小

    # 设置logo
    def set_logo(self):
        pix = QPixmap('../static/img/logo3.png')  # 取图

        lb = QLabel(self)
        lb.setGeometry(22, 8, 100, 100)
        lb.setPixmap(pix)  # 把图片放入label
        lb.setScaledContents(True)  # 自适应QLabel大小

    # 设置左上角的日期信息
    def set_date_msg(self):

        lunar_calendar = change_lunar(self.day)
        week_CH = self.day.week
        week_EN = get_week_EN(self.day.week)
        splist_img = "————————"

        # 阳历
        self.gregorian_calendar_label = QLabel(self.gregorian_calendar, self)
        self.gregorian_calendar_label.setGeometry(150, 6, 300, 40)
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(RATIO(38))  # 设置字体大小
        font1.setFamily("Arial")  # 设置字体
        # font1.setBold(True)  # 加粗
        self.gregorian_calendar_label.setFont(font1)  # 将lb1设置font1格式
        # 星期中文
        self.week_label = QLabel(week_CH, self)
        self.week_label.setGeometry(150, 50, 129, 30)
        font2 = QFont()
        font2.setPixelSize(RATIO(28))
        font2.setFamily("Arial")
        font2.setBold(True)
        self.week_label.setFont(font2)
        # 阴历
        self.lunar_label = QLabel(lunar_calendar, self)
        self.lunar_label.setGeometry(295, 50, 150, 30)
        font3 = QFont()
        font3.setPixelSize(RATIO(28))
        font3.setFamily("Arial")
        font3.setBold(True)
        self.lunar_label.setFont(font3)
        # 星期英文
        self.week_label_EN = QLabel(week_EN, self)
        self.week_label_EN.setGeometry(150, 87, 129, 30)
        font4 = QFont()
        font4.setPixelSize(RATIO(28))
        font4.setFamily("Gabriola")
        font4.setBold(True)
        self.week_label_EN.setFont(font4)
        # 中间的横线
        lb5 = QLabel(splist_img, self)
        lb5.setGeometry(150, 79, 85, 10)
        font5 = QFont()
        font5.setPixelSize(RATIO(33))
        font5.setFamily("Arial")
        # font5.setBold(True)
        lb5.setFont(font5)

    # 设置天气信息
    def set_weather(self, address):
        small = 10
        try:
            # 获取天气信息
            temperature, H_temperature, L_temperature, weather, prompt = get_weather(address)
            # 设置地区字段带更新标识
            text1 = address
            self.address_label = QLabel(self)
            self.address_label.setText(text1)
            self.address_label.setGeometry(560, 5, 25 * len(text1), 35)
            font1 = QFont()  # 创建一个格式对象
            font1.setPixelSize(RATIO(35) -small)  # 设置字体大小
            font1.setFamily("Arial")  # 设置字体
            font1.setBold(True)  # 加粗
            self.address_label.setFont(font1)  # 将lb1设置font1格式

            self.btn_update_address = QPushButton(self)
            self.btn_update_address.setGeometry(565 + 25 * len(text1), 8, 11, 11)
            self.btn_update_address.setStyleSheet("QPushButton{border-image: url(../static/img/天气切换效果.png)}"
                                                  "QPushButton:hover{border-image: url(../static/img/天气切换效果灰.png)}")
            self.btn_update_address.clicked.connect(self.weather_search_bar)

            # 设置天气图标
            pix = QPixmap('../static/img/%s' % weather)  # 取图
            self.weather_img_label = QLabel(self)
            self.weather_img_label.setGeometry(560, 41, 55, 40)
            self.weather_img_label.setPixmap(pix)  # 把图片放入label
            self.weather_img_label.setScaledContents(True)  # 自适应QLabel大小

            # 设置天气类型
            self.weather_label = QLabel(weather, self)
            self.weather_label.setGeometry(560, 80, 100, 35)
            if len(weather) < 2:
                self.weather_label.move(576, 80)
            font2 = QFont()  # 创建一个格式对象
            font2.setPixelSize(RATIO(30) - small)  # 设置字体大小
            font2.setFamily("Arial")  # 设置字体
            font2.setBold(True)  # 加粗
            self.weather_label.setFont(font2)  # 将lb1设置font1格式

            # 设置气温
            self.temperature_label = QLabel(temperature + "℃", self)
            self.temperature_label.setGeometry(633, 18, 200, 65)
            font3 = QFont()  # 创建一个格式对象
            font3.setPixelSize(RATIO(65) - small)  # 设置字体大小
            font3.setFamily("Arial")  # 设置字体
            # font1.setBold(True)  # 加粗
            self.temperature_label.setFont(font3)  # 将lb1设置font1格式

            # 设置最低温到最高温
            self.temperature_L_H_label = QLabel(L_temperature + "~" + H_temperature + "℃", self)
            self.temperature_L_H_label.setGeometry(633, 78, 200, 35)
            font4 = QFont()  # 创建一个格式对象
            font4.setPixelSize(RATIO(35) - small)  # 设置字体大小
            font4.setFamily("Arial")  # 设置字体
            # font1.setBold(True)  # 加粗
            self.temperature_L_H_label.setFont(font4)  # 将lb1设置font1格式

            # 设置提示语句
            self.prompt_label = QLabel(prompt, self)
            self.prompt_label.setGeometry(270, 87, 300, 28)
            font5 = QFont()  # 创建一个格式对象
            font5.setPixelSize(RATIO(28) - small)  # 设置字体大小
            font5.setFamily("Arial")  # 设置字体
            font5.setBold(True)  # 加粗
            self.prompt_label.setFont(font5)  # 将lb1设置font1格式


        except:
            pass

    # 右上角的三个操作按钮
    def set_action_bar(self):
        # 设置关闭按钮
        btn_close = QPushButton(self)
        btn_close.setGeometry(770, 0, 30, 30)
        btn_close.setStyleSheet("QPushButton{border-image: url(../static/img/关闭.png)}"
                                "QPushButton:hover{border-image: url(../static/img/关闭2.png)}")
        btn_close.clicked.connect(self.close)
        # 设置设置按钮
        btn_set = QPushButton(self)
        btn_set.setGeometry(740, 0, 30, 30)
        btn_set.setStyleSheet("QPushButton{border-image: url(../static/img/设置.png)}"
                              "QPushButton:hover{border-image: url(../static/img/设置2.png)}")
        btn_set.clicked.connect(self.open_setting_window)
        # 设置最小化按钮
        btn_min = QPushButton(self)
        btn_min.setGeometry(710, 0, 30, 30)
        btn_min.setStyleSheet("QPushButton{border-image: url(../static/img/最小化.png)}"
                              "QPushButton:hover{border-image: url(../static/img/最小化2.png)}")
        btn_min.clicked.connect(self.set_small)

    # 重写最小化函数，最小化时关闭多余窗口
    def set_small(self):
        self.thread.close_window_signal.emit("")
        self.showMinimized()

    # 设置中间框中的内容
    def set_grey_frame(self):

        set_x = 30

        # 设置灰色框
        pix = QPixmap('../static/img/灰色框.png')  # 取图
        frame = QLabel(self)
        frame.setGeometry(0, 120, 800, 45)
        frame.setPixmap(pix)  # 把图片放入label
        frame.setScaledContents(True)  # 自适应QLabel大小

        # 设置最左边双箭头
        doubel_arrow_left = QPushButton(self)
        doubel_arrow_left.setGeometry(240 - set_x, 120, 45, 45)
        doubel_arrow_left.setStyleSheet("QPushButton{border-image: url(../static/img/双左箭头1.png)}"
                                        "QPushButton:hover{border-image: url(../static/img/双左箭头2.png)}")
        doubel_arrow_left.clicked.connect(self.change_clendar_left_year)

        # 设置左边单箭头
        arrow_left = QPushButton(self)
        arrow_left.setGeometry(285 - set_x, 120, 45, 45)
        arrow_left.setStyleSheet("QPushButton{border-image: url(../static/img/单左箭头1.png)}"
                                 "QPushButton:hover{border-image: url(../static/img/单左箭头2.png)}")
        arrow_left.clicked.connect(self.change_clendar_left_mouth)

        # 设置右边单箭头
        arrow_right = QPushButton(self)
        arrow_right.setGeometry(515 - set_x, 120, 45, 45)
        arrow_right.setStyleSheet("QPushButton{border-image: url(../static/img/单右箭头1.png)}"
                                  "QPushButton:hover{border-image: url(../static/img/单右箭头2.png)}")
        arrow_right.clicked.connect(self.change_clendar_right_mouth)
        # 设置右边双箭头
        doubel_arrow_right = QPushButton(self)
        doubel_arrow_right.setGeometry(560 - set_x, 120, 45, 45)
        doubel_arrow_right.setStyleSheet("QPushButton{border-image: url(../static/img/双右箭头1.png)}"
                                         "QPushButton:hover{border-image: url(../static/img/双右箭头2.png)}")
        doubel_arrow_right.clicked.connect(self.change_clendar_right_year)

        # 设置中间的日期显示
        self.middle_date_label = QLabel(self.search_mouth, self)
        self.middle_date_label.setGeometry(360 - set_x, 120, 150, 45)
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(RATIO(25))  # 设置字体大小
        font1.setFamily("NSimSun")  # 设置字体
        font1.setBold(True)  # 加粗
        self.middle_date_label.setFont(font1)  # 将lb1设置font1格式

        self.btn_update_date = QPushButton(self)
        self.btn_update_date.setGeometry(465, 130, 11, 11)
        self.btn_update_date.setStyleSheet("QPushButton{border-image: url(../static/img/天气切换效果.png)}"
                                           "QPushButton:hover{border-image: url(../static/img/天气切换效果灰.png)}")
        self.btn_update_date.clicked.connect(self.calendar_search_bar)

    # 修改小按钮的位置
    def update_small_search_btn(self):
        if len(self.middle_date_label.text()) == 8:
            self.btn_update_date.move(465, 130)
        else:
            self.btn_update_date.move(450, 130)

    # 设置搜索框
    def set_search_bar(self):
        self.search_edit = QLineEdit(self)
        self.search_edit.setGeometry(597, 123, 200, 39)
        self.search_edit.setPlaceholderText("请输入事件关键字")
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(19)  # 设置字体大小
        font1.setFamily("Microsoft YaHei")  # 设置字体
        # font1.setBold(True)  # 加粗
        self.search_edit.setFont(font1)  # 将lb1设置font1格式
        # "background:transparent;border-width:0;border-style:outset"
        self.search_edit.setStyleSheet(
            "QLineEdit{background: rgba(255, 255, 255, 0.5);border-style: outset; border-width: 3px; border-color: rgba(105,105,105, 1);}"
            "QLineEdit:focus{background: rgba(255, 255, 255, 0.8);border-style: outset; border-width: 3px; border-color: rgba(70,130,180, 0.8);}")
        self.search_edit.returnPressed.connect(self.search)
        # 设置右边搜索按钮
        search_btn = QPushButton(self)
        search_btn.setGeometry(760, 126, 33, 33)
        search_btn.setStyleSheet("QPushButton{border-image: url(../static/img/查看2.png)}"
                                 "QPushButton:hover{border-image: url(../static/img/查看3.png)}")
        search_btn.clicked.connect(self.search)

    # 设置日历字段
    def set_field(self):
        # 设置教学周字段
        text1 = "教学周"
        teach_label = QLabel(text1, self)
        teach_label.setGeometry(6, 163, 90, 50)
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(RATIO(25))  # 设置字体大小
        font1.setFamily("NSimSun")  # 设置字体
        font1.setBold(True)  # 加粗
        teach_label.setFont(font1)  # 将lb1设置font1格式

        # 设置星期字段
        week_list = ["一", "二", "三", "四", "五", "六", "日"]
        for i in range(7):
            text2 = week_list[i]
            week_label = QLabel(text2, self)
            week_label.setGeometry(115 + i * 103, 161, 50, 50)
            font1 = QFont()  # 创建一个格式对象
            font1.setPixelSize(RATIO(33))  # 设置字体大小
            font1.setFamily("NSimSun")  # 设置字体
            font1.setBold(True)  # 加粗
            week_label.setFont(font1)  # 将lb1设置font1格式

        # 设置教学周间隔直线

        pix = QPixmap('../static/img/直线.png')  # 取图

        lb = QLabel(self)
        lb.setGeometry(90, 165, 3, 435)
        lb.setPixmap(pix)  # 把图片放入label
        lb.setScaledContents(True)  # 自适应QLabel大小

    # 设置日历和教学周
    def set_calendar(self):
        mouth = mouth_object()
        mouth.get_msg(self.search_mouth)
        msg = mouth.msg
        day_list = msg.split("\n")
        day_object_list = []
        for i in day_list[0:-1]:
            day = day_object()
            day.gregorian_calendar = i.split(":")[0]
            day.lunar_calendar = i.split(":")[1].split(",")[0]
            day.week = i.split(":")[1].split(",")[1]
            day.solar_term = i.split(":")[1].split(",")[2]
            day.statutory_holidays = i.split(":")[1].split(",")[3]
            day_object_list.append(day)
        week_list = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]
        count = 0
        count_1 = 1
        dict_1 = {}  # 每行所有日期
        list_1 = []
        for i in range(6):
            for j in range(7):
                date = calendar_object(99 + j * 103, 211 + i * 64, 60, 60)
                self.calendar_list.append(date)
                if count < len(day_object_list):
                    week = week_list[j]
                    if day_object_list[count].week == week:
                        date.day = day_object_list[count]
                        o_1 = 0
                        o_2 = 0
                        o_3 = 0
                        o_4 = 1
                        o_5 = 0

                        if having_event(day_object_list[count].gregorian_calendar.split("年")[0] + "," +
                                        day_object_list[count].gregorian_calendar.split("年")[1].split("月")[0] + "," +
                                        day_object_list[count].gregorian_calendar.split("年")[1].split("月")[1].split(
                                            "日")[0]):
                            o_4 = 0

                        if day_object_list[count].gregorian_calendar != self.gregorian_calendar:
                            o_1 = 1

                        date.set_label(self, o_1, o_2, o_3, o_4, o_5)
                        list_1.append(day_object_list[count].gregorian_calendar)
                        count = count + 1
                    else:
                        date.day = get_day("2022年10月1日")
                        o_1 = 1
                        o_2 = 1
                        o_3 = 1
                        o_4 = 1
                        o_5 = 1
                        date.set_label(self, o_1, o_2, o_3, o_4, o_5)
                else:
                    date.day = get_day("2022年10月1日")
                    o_1 = 1
                    o_2 = 1
                    o_3 = 1
                    o_4 = 1
                    o_5 = 1
                    date.set_label(self, o_1, o_2, o_3, o_4, o_5)
                date.signal.connect(self.open_schedule_window)
            dict_1.update({str(count_1): list_1})
            count_1 = count_1 + 1
            list_1 = []
        # 设置教学周
        teaching_dict = get_teaching_week_dict(read_setting("教学周"), read_setting("持续时间"))
        is_teaching = False  # 判断这页有没有教学周

        # 循环每行
        for x, y in dict_1.items():
            is_find_1 = False
            # 找每行中有没有日期是在教学周中的
            if len(y) > 0:
                for i in y:
                    is_find = False
                    for a, b in teaching_dict.items():
                        if i in b:  # 找到对应的那一天
                            is_find = True
                            is_find_1 = True
                            is_teaching = True
                            teaching_week = teaching_week_object(34, 207 + (int(x) - 1) * 64, 60, 60, a)
                            if self.day.gregorian_calendar in y:
                                teaching_week.set_label(self, 1, 1)
                                self.teaching_week_list.append(teaching_week)
                            else:
                                teaching_week.set_label(self, 0, 1)
                                self.teaching_week_list.append(teaching_week)
                            break

                    if is_find:  # 找到就换下一行
                        break
                if is_find_1 == False:  # 没找到
                    teaching_week = teaching_week_object(34, 207 + (int(x) - 1) * 64, 60, 60, "0")
                    teaching_week.set_label(self, 0, 0)
                    self.teaching_week_list.append(teaching_week)
            else:
                teaching_week = teaching_week_object(34, 207 + (int(x) - 1) * 64, 60, 60, "0")
                teaching_week.set_label(self, 0, 0)
                self.teaching_week_list.append(teaching_week)

        self.rest_label = QLabel("休", self)
        self.rest_label.setGeometry(15, 350, 60, 60)
        font1 = QFont()  # 创建一个格式对象
        font1.setPixelSize(RATIO(60))  # 设置字体大小
        font1.setFamily("Arial")  # 设置字体
        font1.setBold(True)  # 加粗
        self.rest_label.setFont(font1)  # 将lb1设置font1格式
        if is_teaching == False:  # 如果没有教学周则设置休
            self.rest_label.show()
        else:
            self.rest_label.hide()

    # 获取提醒列表
    def get_event_list(self):

        self.remind_event_list = []

        with open("../event/event.json", "r") as f:
            events = json.load(f)
        for id, event in events.items():
            if event["remind_msg"].split(",")[0] == "无":
                continue
            elif event["remind_msg"].split(",")[0] == "无提前":
                re_time = datetime.datetime(1911, 11, 11, 0, 0)
            elif event["remind_msg"].split(",")[0] == "0分钟":
                re_time = datetime.datetime(int(event["start_time"].split(",")[0]),
                                            int(event["start_time"].split(",")[1]),
                                            int(event["start_time"].split(",")[2]),
                                            int(event["start_time"].split(",")[3]),
                                            int(event["start_time"].split(",")[4])) - datetime.timedelta(minutes=0)
            elif event["remind_msg"].split(",")[0] == "5分钟":
                re_time = datetime.datetime(int(event["start_time"].split(",")[0]),
                                            int(event["start_time"].split(",")[1]),
                                            int(event["start_time"].split(",")[2]),
                                            int(event["start_time"].split(",")[3]),
                                            int(event["start_time"].split(",")[4])) - datetime.timedelta(minutes=5)
            elif event["remind_msg"].split(",")[0] == "15分钟":
                re_time = datetime.datetime(int(event["start_time"].split(",")[0]),
                                            int(event["start_time"].split(",")[1]),
                                            int(event["start_time"].split(",")[2]),
                                            int(event["start_time"].split(",")[3]),
                                            int(event["start_time"].split(",")[4])) - datetime.timedelta(minutes=15)
            elif event["remind_msg"].split(",")[0] == "30分钟":
                re_time = datetime.datetime(int(event["start_time"].split(",")[0]),
                                            int(event["start_time"].split(",")[1]),
                                            int(event["start_time"].split(",")[2]),
                                            int(event["start_time"].split(",")[3]),
                                            int(event["start_time"].split(",")[4])) - datetime.timedelta(minutes=30)
            elif event["remind_msg"].split(",")[0] == "1小时":
                re_time = datetime.datetime(int(event["start_time"].split(",")[0]),
                                            int(event["start_time"].split(",")[1]),
                                            int(event["start_time"].split(",")[2]),
                                            int(event["start_time"].split(",")[3]),
                                            int(event["start_time"].split(",")[4])) - datetime.timedelta(hours=1)
            elif event["remind_msg"].split(",")[0] == "12小时":
                re_time = datetime.datetime(int(event["start_time"].split(",")[0]),
                                            int(event["start_time"].split(",")[1]),
                                            int(event["start_time"].split(",")[2]),
                                            int(event["start_time"].split(",")[3]),
                                            int(event["start_time"].split(",")[4])) - datetime.timedelta(hours=12)
            elif event["remind_msg"].split(",")[0] == "1天":
                re_time = datetime.datetime(int(event["start_time"].split(",")[0]),
                                            int(event["start_time"].split(",")[1]),
                                            int(event["start_time"].split(",")[2]),
                                            int(event["start_time"].split(",")[3]),
                                            int(event["start_time"].split(",")[4])) - datetime.timedelta(days=1)
            else:
                re_time = datetime.datetime(int(event["start_time"].split(",")[0]),
                                            int(event["start_time"].split(",")[1]),
                                            int(event["start_time"].split(",")[2]),
                                            int(event["start_time"].split(",")[3]),
                                            int(event["start_time"].split(",")[4])) - datetime.timedelta(days=7)

            # 当前时间
            now_time = datetime.datetime(datetime.date.today().year, datetime.date.today().month
                                         , datetime.date.today().day, datetime.datetime.now().hour,
                                         datetime.datetime.now().minute)
            # 判断当前时间是否在范围时间内
            if now_time < re_time:
                self.remind_event_list.append(
                    id + "," + str(re_time.year) + "," + str(re_time.month) + "," + str(re_time.day) + "," + str(
                        re_time.hour) + "," + str(re_time.minute))

            if event["remind_msg"].split(",")[1] == "无":
                continue
            elif event["remind_msg"].split(",")[1] == "每天":
                s_time = datetime.datetime(int(event["start_time"].split(",")[0]),
                                           int(event["start_time"].split(",")[1]),
                                           int(event["start_time"].split(",")[2]),
                                           int(event["start_time"].split(",")[3]),
                                           int(event["start_time"].split(",")[4]))

                e_time = datetime.datetime(int(event["end_time"].split(",")[0]),
                                           int(event["end_time"].split(",")[1]),
                                           int(event["end_time"].split(",")[2]),
                                           int(event["end_time"].split(",")[3]),
                                           int(event["end_time"].split(",")[4]))

                re_time = datetime.datetime(int(event["start_time"].split(",")[0]),
                                            int(event["start_time"].split(",")[1]),
                                            int(event["start_time"].split(",")[2]),
                                            int(event["remind_msg"].split(",")[2].split(":")[0]),
                                            int(event["remind_msg"].split(",")[2].split(":")[1]))

                if re_time < s_time:
                    re_time = re_time + datetime.timedelta(days=1)

                while s_time <= re_time <= e_time:
                    if now_time < re_time:
                        self.remind_event_list.append(
                            id + "," + str(re_time.year) + "," + str(re_time.month) + "," + str(
                                re_time.day) + "," + str(
                                re_time.hour) + "," + str(re_time.minute))
                    re_time = re_time + datetime.timedelta(days=1)

                # 提醒检测并触发函数
            else:
                s_time = datetime.datetime(int(event["start_time"].split(",")[0]),
                                           int(event["start_time"].split(",")[1]),
                                           int(event["start_time"].split(",")[2]),
                                           int(event["start_time"].split(",")[3]),
                                           int(event["start_time"].split(",")[4]))

                e_time = datetime.datetime(int(event["end_time"].split(",")[0]),
                                           int(event["end_time"].split(",")[1]),
                                           int(event["end_time"].split(",")[2]),
                                           int(event["end_time"].split(",")[3]),
                                           int(event["end_time"].split(",")[4]))

                re_time = datetime.datetime(int(event["start_time"].split(",")[0]),
                                            int(event["start_time"].split(",")[1]),
                                            int(event["start_time"].split(",")[2]),
                                            int(event["remind_msg"].split(",")[2].split(":")[0]),
                                            int(event["remind_msg"].split(",")[2].split(":")[1]))

                if re_time < s_time:
                    re_time = re_time + datetime.timedelta(days=1)
                while s_time <= re_time <= e_time:
                    if now_time < re_time and str(re_time.weekday() + 1) in event["remind_msg"].split(",")[3]:
                        self.remind_event_list.append(
                            id + "," + str(re_time.year) + "," + str(re_time.month) + "," + str(
                                re_time.day) + "," + str(
                                re_time.hour) + "," + str(re_time.minute))
                    re_time = re_time + datetime.timedelta(days=1)

    # 修改搜索框-天气
    def weather_search_bar(self):
        self.search_bar_type = 1
        self.search_edit.setStyleSheet(
            "QLineEdit{background: rgba(255, 255, 255, 0.5);border-style: outset; border-width: 3px; border-color: rgba(105,105,105, 1);}"
            "QLineEdit:focus{background: rgba(255, 255, 255, 0.8);border-style: outset; border-width: 3px; border-color: rgba(0,128,0, 0.8);}")
        self.search_edit.clear()
        self.search_edit.setPlaceholderText("请输入地址")
        self.search_edit.setFocus()

    # 修改搜索框-事件
    def event_search_bar(self):
        self.search_bar_type = 0
        self.search_edit.setStyleSheet(
            "QLineEdit{background: rgba(255, 255, 255, 0.5);border-style: outset; border-width: 3px; border-color: rgba(105,105,105, 1);}"
            "QLineEdit:focus{background: rgba(255, 255, 255, 0.8);border-style: outset; border-width: 3px; border-color: rgba(70,130,180, 0.8);}")
        self.search_edit.setPlaceholderText("请输入事件关键字")

    # 修改搜索框-日期
    def calendar_search_bar(self):
        self.search_bar_type = 2
        self.search_edit.setStyleSheet(
            "QLineEdit{background: rgba(255, 255, 255, 0.5);border-style: outset; border-width: 3px; border-color: rgba(105,105,105, 1);}"
            "QLineEdit:focus{background: rgba(255, 255, 255, 0.8);border-style: outset; border-width: 3px; border-color: rgba(102,51,204, 0.8);}")
        self.search_edit.clear()
        self.search_edit.setPlaceholderText("请输入日期")
        self.search_edit.setFocus()

    # 搜索
    def search(self):

        if self.search_bar_type == 0:
            self.thread.open_search_window(self.search_edit.text())
        elif self.search_bar_type == 1:

            try:
                get_weather(self.search_edit.text())
                self.change_weather(self.search_edit.text())
            except:
                msg_box = QMessageBox(QMessageBox.Critical, '错误', '未找到指定地点或网络未连接')
                font1 = QFont()  # 创建一个格式对象
                font1.setPixelSize(RATIO(20))  # 设置字体大小
                font1.setFamily("Microsoft YaHei")  # 设置字体
                msg_box.setFont(font1)
                msg_box.exec_()

        else:
            if check_date_formate(self.search_edit.text()) and 1901 <= int(
                    self.search_edit.text().split("年")[0]) <= 2100:

                self.change_clendar_signal(self.search_edit.text())

            else:
                msg_box = QMessageBox(QMessageBox.Critical, '错误', '时间溢界或格式错误<br>正确格式：（x年x月）')
                font1 = QFont()  # 创建一个格式对象
                font1.setPixelSize(RATIO(20))  # 设置字体大小
                font1.setFamily("Microsoft YaHei")  # 设置字体
                msg_box.setFont(font1)
                msg_box.exec_()
        self.event_search_bar()
        self.search_edit.clear()

    # 提醒检测并触发函数
    def remind(self):
        is_up = False
        for msg in self.remind_event_list:
            if str(datetime.datetime.now().year) == msg.split(",")[1] and str(datetime.datetime.now().month) == \
                    msg.split(",")[
                        2] and str(datetime.datetime.now().day) == msg.split(",")[3] and str(
                datetime.datetime.now().hour) == \
                    msg.split(",")[4] and str(datetime.datetime.now().minute) == msg.split(",")[5]:
                self.open_remind_window_signal.emit(msg.split(",")[0])
                is_up = True
        if is_up:
            self.get_event_list()

    """打开窗口函数"""

    # 打开修改天气窗口
    def open_change_weather_window(self):
        self.change_address_window_signal.emit("")

    # 打开搜索时间按钮
    def open_change_time_window(self):
        self.change_time_window_signal.emit("")

    # 打开设置界面
    def open_setting_window(self):
        self.setting_window_signal.emit("")

    # 打开日程对话窗
    def open_schedule_window(self, position):

        position_1 = get_position(self, position) + "," + position.split(",")[3] + "," + position.split(",")[4] + "," + \
                     position.split(",")[5]

        self.open_schedule_window_signal.emit(position_1)

    """修改函数"""

    # 修改天气
    def change_weather(self, address):
        try:
            self.address = address
            # 获取天气信息
            temperature, H_temperature, L_temperature, weather, prompt = get_weather(address)
            # 设置地区字段带更新标识
            text1 = address
            self.address_label.setText(text1)
            self.address_label.setGeometry(560, 5, 25 * len(text1), 35)

            self.btn_update_address.setGeometry(565 + 25 * len(text1), 8, 10, 10)

            # 设置天气图标
            pix = QPixmap('../static/img/%s' % weather)  # 取图
            self.weather_img_label.setGeometry(560, 41, 55, 40)
            self.weather_img_label.setPixmap(pix)  # 把图片放入label
            self.weather_img_label.setScaledContents(True)  # 自适应QLabel大小

            # 设置天气类型
            self.weather_label.setText(weather)

            # 设置气温
            self.temperature_label.setText(temperature + "℃")

            # 设置最低温到最高温
            self.temperature_L_H_label.setText(L_temperature + "~" + H_temperature + "℃")

            # 设置提示语句
            self.prompt_label.setText(prompt)
            return True

        except:
            return False

    # 日历加一年
    def change_clendar_right_year(self):
        self.search_mouth = str(int(self.search_mouth.split("年")[0]) + 1) + "年" + self.search_mouth.split("年")[1]
        if int(self.search_mouth.split("年")[0]) > 2100:
            self.search_mouth = "2100年" + self.search_mouth.split("年")[1]

        self.change_clendar()

    # 日历减一年
    def change_clendar_left_year(self):
        self.search_mouth = str(int(self.search_mouth.split("年")[0]) - 1) + "年" + self.search_mouth.split("年")[1]
        if int(self.search_mouth.split("年")[0]) < 1901:
            self.search_mouth = "1901年" + self.search_mouth.split("年")[1]

        self.change_clendar()

    # 日历加一个月
    def change_clendar_right_mouth(self):
        self.search_mouth = self.search_mouth.split("年")[0] + "年" + \
                            str(int(self.search_mouth.split("年")[1].split("月")[0]) + 1) + "月"
        if int(self.search_mouth.split("年")[1].split("月")[0]) > 12:
            self.search_mouth = str(int(self.search_mouth.split("年")[0]) + 1) + "年1月"
        if int(self.search_mouth.split("年")[0]) > 2100:
            self.search_mouth = "2100年12月"

        self.change_clendar()

    # 日历减一个月
    def change_clendar_left_mouth(self):
        self.search_mouth = self.search_mouth.split("年")[0] + "年" + \
                            str(int(self.search_mouth.split("年")[1].split("月")[0]) - 1) + "月"
        if int(self.search_mouth.split("年")[1].split("月")[0]) < 1:
            self.search_mouth = str(int(self.search_mouth.split("年")[0]) - 1) + "年12月"
        if int(self.search_mouth.split("年")[0]) < 1901:
            self.search_mouth = "1901年1月"
        self.change_clendar()

    # 日历修改函数
    def change_clendar(self):
        mouth = mouth_object()
        mouth.get_msg(self.search_mouth)
        self.middle_date_label.setText(self.search_mouth)
        self.update_small_search_btn()
        msg = mouth.msg
        day_list = msg.split("\n")
        day_object_list = []
        for i in day_list[0:-1]:
            day = day_object()
            day.gregorian_calendar = i.split(":")[0]
            day.lunar_calendar = i.split(":")[1].split(",")[0]
            day.week = i.split(":")[1].split(",")[1]
            day.solar_term = i.split(":")[1].split(",")[2]
            day.statutory_holidays = i.split(":")[1].split(",")[3]
            day_object_list.append(day)
        week_list = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]
        count = 0
        count_1 = 1
        dict_1 = {}  # 每行所有日期
        list_1 = []
        for i in range(6):
            for j in range(7):
                if count < len(day_object_list):
                    week = week_list[j]
                    if day_object_list[count].week == week:
                        # 修改阴历
                        self.calendar_list[7 * i + j].day = day_object_list[count]
                        self.calendar_list[7 * i + j].lb1.setText(day_object_list[count]
                                                                  .gregorian_calendar.split("日")[0].split("月")[1])
                        # if len(day_object_list[count].gregorian_calendar.split("日")[0].split("月")[1]) == 2:
                        #     self.calendar_list[7 * i + j].lb1.move(113 + j * 103, 216 + i * 64)
                        # else:
                        #     self.calendar_list[7 * i + j].lb1.move(121 + j * 103, 216 + i * 64)
                        self.calendar_list[7 * i + j].lb1.show()
                        # 修改农历
                        if day_object_list[count].statutory_holidays != "无":  # 获取下面的显示的农历节气节日文本
                            text = day_object_list[count].statutory_holidays
                        elif day_object_list[count].solar_term != "无":
                            text = day_object_list[count].solar_term
                        else:
                            if day_object_list[count].lunar_calendar.split("月")[1] == "初一":
                                text = day_object_list[count].lunar_calendar.split("月")[0] + "月"
                            else:
                                text = day_object_list[count].lunar_calendar.split("月")[1]

                        self.calendar_list[7 * i + j].lb2.setText(text)
                        self.calendar_list[7 * i + j].lb2.show()

                        if having_event(day_object_list[count].gregorian_calendar.split("年")[0] + "," +
                                        day_object_list[count].gregorian_calendar.split("年")[1].split("月")[0] + "," +
                                        day_object_list[count].gregorian_calendar.split("年")[1].split("月")[1].split(
                                            "日")[0]):
                            self.calendar_list[7 * i + j].lb3.show()
                        else:
                            self.calendar_list[7 * i + j].lb3.hide()

                        if day_object_list[count].gregorian_calendar == self.gregorian_calendar:
                            self.calendar_list[7 * i + j].lb.show()

                        else:
                            self.calendar_list[7 * i + j].lb.hide()

                        self.calendar_list[7 * i + j].btn.show()

                        list_1.append(day_object_list[count].gregorian_calendar)
                        count = count + 1
                    else:
                        self.calendar_list[7 * i + j].lb.hide()
                        self.calendar_list[7 * i + j].lb1.hide()
                        self.calendar_list[7 * i + j].lb2.hide()
                        self.calendar_list[7 * i + j].lb3.hide()
                        self.calendar_list[7 * i + j].btn.hide()
                else:
                    self.calendar_list[7 * i + j].lb.hide()
                    self.calendar_list[7 * i + j].lb1.hide()
                    self.calendar_list[7 * i + j].lb2.hide()
                    self.calendar_list[7 * i + j].lb3.hide()
                    self.calendar_list[7 * i + j].btn.hide()
            dict_1.update({str(count_1): list_1})
            count_1 = count_1 + 1
            list_1 = []
        # 设置教学周
        teaching_dict = get_teaching_week_dict(read_setting("教学周"), read_setting("持续时间"))
        is_teaching = False  # 判断这页有没有教学周
        # 循环每行
        for x, y in dict_1.items():
            # 找每行中有没有日期是在教学周中的
            if len(y) > 0:
                for i in y:
                    is_find = False
                    for a, b in teaching_dict.items():
                        if i in b:  # 找到对应的那一天
                            is_find = True
                            is_teaching = True
                            self.teaching_week_list[int(x) - 1].lb1.setText(a)

                            self.teaching_week_list[int(x) - 1].lb1.show()
                            if self.day.gregorian_calendar in y:
                                self.teaching_week_list[int(x) - 1].lb.show()
                            else:
                                self.teaching_week_list[int(x) - 1].lb.hide()
                    if is_find:  # 找到就换下一行
                        break
                    else:
                        self.teaching_week_list[int(x) - 1].lb.hide()
                        self.teaching_week_list[int(x) - 1].lb1.hide()
            else:
                self.teaching_week_list[int(x) - 1].lb.hide()
                self.teaching_week_list[int(x) - 1].lb1.hide()

        if is_teaching == False:  # 如果没有教学周则设置休
            self.rest_label.show()
        else:
            self.rest_label.hide()

    # 日历修改函数修改版
    def change_clendar_signal(self, time):
        self.search_mouth = time
        self.middle_date_label.setText(time)
        self.update_small_search_btn()
        mouth = mouth_object()
        mouth.get_msg(time)
        msg = mouth.msg
        day_list = msg.split("\n")
        day_object_list = []
        for i in day_list[0:-1]:
            day = day_object()
            day.gregorian_calendar = i.split(":")[0]
            day.lunar_calendar = i.split(":")[1].split(",")[0]
            day.week = i.split(":")[1].split(",")[1]
            day.solar_term = i.split(":")[1].split(",")[2]
            day.statutory_holidays = i.split(":")[1].split(",")[3]
            day_object_list.append(day)
        week_list = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]
        count = 0
        count_1 = 1
        dict_1 = {}  # 每行所有日期
        list_1 = []
        for i in range(6):
            for j in range(7):
                if count < len(day_object_list):
                    week = week_list[j]
                    if day_object_list[count].week == week:
                        self.calendar_list[7 * i + j].day = day_object_list[count]
                        # 修改阴历
                        self.calendar_list[7 * i + j].lb1.setText(day_object_list[count]
                                                                  .gregorian_calendar.split("日")[0].split("月")[1])
                        self.calendar_list[7 * i + j].lb1.show()
                        # 修改农历
                        if day_object_list[count].statutory_holidays != "无":  # 获取下面的显示的农历节气节日文本
                            text = day_object_list[count].statutory_holidays
                        elif day_object_list[count].solar_term != "无":
                            text = day_object_list[count].solar_term
                        else:
                            if day_object_list[count].lunar_calendar.split("月")[1] == "初一":
                                text = day_object_list[count].lunar_calendar.split("月")[0] + "月"
                            else:
                                text = day_object_list[count].lunar_calendar.split("月")[1]

                        self.calendar_list[7 * i + j].lb2.setText(text)
                        self.calendar_list[7 * i + j].lb2.show()

                        if having_event(day_object_list[count].gregorian_calendar.split("年")[0] + "," +
                                        day_object_list[count].gregorian_calendar.split("年")[1].split("月")[0] + "," +
                                        day_object_list[count].gregorian_calendar.split("年")[1].split("月")[1].split(
                                            "日")[0]):
                            self.calendar_list[7 * i + j].lb3.show()
                        else:
                            self.calendar_list[7 * i + j].lb3.hide()

                        if day_object_list[count].gregorian_calendar == self.gregorian_calendar:
                            self.calendar_list[7 * i + j].lb.show()

                        else:
                            self.calendar_list[7 * i + j].lb.hide()

                        self.calendar_list[7 * i + j].btn.show()

                        list_1.append(day_object_list[count].gregorian_calendar)
                        count = count + 1
                    else:
                        self.calendar_list[7 * i + j].lb.hide()
                        self.calendar_list[7 * i + j].lb1.hide()
                        self.calendar_list[7 * i + j].lb2.hide()
                        self.calendar_list[7 * i + j].lb3.hide()
                        self.calendar_list[7 * i + j].btn.hide()
                else:
                    self.calendar_list[7 * i + j].lb.hide()
                    self.calendar_list[7 * i + j].lb1.hide()
                    self.calendar_list[7 * i + j].lb2.hide()
                    self.calendar_list[7 * i + j].lb3.hide()
                    self.calendar_list[7 * i + j].btn.hide()
            dict_1.update({str(count_1): list_1})
            count_1 = count_1 + 1
            list_1 = []
        # 设置教学周
        teaching_dict = get_teaching_week_dict(read_setting("教学周"), read_setting("持续时间"))
        is_teaching = False  # 判断这页有没有教学周
        # 循环每行
        for x, y in dict_1.items():
            # 找每行中有没有日期是在教学周中的
            if len(y) > 0:
                for i in y:
                    is_find = False
                    for a, b in teaching_dict.items():
                        if i in b:  # 找到对应的那一天
                            is_find = True
                            is_teaching = True
                            self.teaching_week_list[int(x) - 1].lb1.setText(a)

                            self.teaching_week_list[int(x) - 1].lb1.show()
                            if self.day.gregorian_calendar in y:
                                self.teaching_week_list[int(x) - 1].lb.show()
                            else:
                                self.teaching_week_list[int(x) - 1].lb.hide()
                    if is_find:  # 找到就换下一行
                        break
                    else:
                        self.teaching_week_list[int(x) - 1].lb.hide()
                        self.teaching_week_list[int(x) - 1].lb1.hide()
            else:
                self.teaching_week_list[int(x) - 1].lb.hide()
                self.teaching_week_list[int(x) - 1].lb1.hide()

        if is_teaching == False:  # 如果没有教学周则设置休
            self.rest_label.show()
        else:
            self.rest_label.hide()

    # 修改背景函数
    def change_background(self, background_img):
        pix = QPixmap('../static/img/%s' % background_img)  # 取图
        self.background.setPixmap(pix)

    # 修改教学周函数
    def change_teaching_week_address(self):
        self.change_clendar()
        self.address = read_setting("地址")
        self.change_weather(self.address)

    # 点击保存或者删除事件时刷新提醒列表以及日历主界面
    def update_main_window_remind_event(self):
        self.change_clendar()
        self.get_event_list()

    # 定时刷新页面元素
    def time_update(self):
        # 定时刷新天气
        self.change_weather(self.address)
        # 定时刷新左上角的日历信息
        if self.gregorian_calendar != "%s年%s月%s日" % (datetime.date.today().year, datetime.date.today().month
                                                     , datetime.date.today().day):
            self.gregorian_calendar = "%s年%s月%s日" % (datetime.date.today().year, datetime.date.today().month
                                                     , datetime.date.today().day)
            self.gregorian_calendar_label.setText(self.gregorian_calendar)
            self.day = get_day(self.gregorian_calendar)
            self.week_label.setText(self.day.week)
            self.lunar_label.setText(change_lunar(self.day))
            self.week_label_EN.setText(get_week_EN(self.day.week))

    # 重置函数
    def reset(self):

        self.thread.w_setting.close()

        remind_box = QMessageBox.question(self, '系统重置', '你确定要重置本系统吗?', QMessageBox.Yes | QMessageBox.No,
                                          QMessageBox.No)  # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
        if remind_box == QMessageBox.Yes:
            pass
        else:
            return

        remind_box = QMessageBox.question(self, '再次确认', '你真的确定吗?', QMessageBox.Yes | QMessageBox.No,
                                          QMessageBox.No)  # "退出"代表的是弹出框的标题,"你确认退出.."表示弹出框的内容
        if remind_box == QMessageBox.Yes:
            pass
        else:
            return

        # 删除视频
        name_list = os.listdir('../event/videos')
        for i in name_list:
            shutil.rmtree("../event/videos/%s" % i)

        # 删除照片
        name_list = os.listdir('../event/images')
        for i in name_list:
            shutil.rmtree("../event/images/%s" % i)

        # 重置事件
        with open("../event/event.json", "r") as f:
            data = json.load(f)

        t = {"s_0":data["s_0"]}

        with open("../event/event.json", "w") as f:
            f.write(json.dumps(t))

        # 重置设置参数
        update_setting("背景", "背景4")
        update_setting("地址", "南京")
        update_setting("教学周", "2022年10月1日")
        update_setting("持续时间", "0")
        update_setting("事件数", "1")
        self.change_clendar()


    """去除操作栏函数重写"""

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            self.thread.close_window_signal.emit("")
            self.event_search_bar()
            self.search_edit.clearFocus()
            self.m_flag = True
            self.m_Position = event.globalPos() - self.pos()  # 获取鼠标相对窗口的位置
            event.accept()

    def mouseMoveEvent(self, QMouseEvent):
        try:
            if Qt.LeftButton and self.m_flag:
                self.move(QMouseEvent.globalPos() - self.m_Position)  # 更改窗口位置
                QMouseEvent.accept()
        except Exception:
            pass

    def mouseReleaseEvent(self, QMouseEvent):
        self.m_flag = False
        self.setCursor(QCursor(Qt.ArrowCursor))

    # 重写页面关闭函数
    def closeEvent(self, event):
        sys.exit(app.exec_())


if __name__ == '__main__':

    w,h = get_real_resolution()

    if h > 1080 and w > 1920:
        QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)

    app = QApplication(sys.argv)

    w = MainWindow()

    w.show()

    app.exec()
